package com.itheima.reggie.common;

import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.itheima.reggie.entity.Category;

import java.time.LocalDateTime;

public class TestObjMapper {
    public static void main(String[] args) throws JsonProcessingException {
        JacksonObjectMapper jacksonObjectMapper = new JacksonObjectMapper();
        ObjectMapper objectMapper = new ObjectMapper();

        Category category = new Category();
        category.setCreateTime(LocalDateTime.now());
        category.setUpdateTime(LocalDateTime.now());
        category.setId(IdWorker.getId());
        category.setCreateUser(1L);
        category.setName("666");
        String s = jacksonObjectMapper.writeValueAsString(category);
        String s1 = objectMapper.writeValueAsString(category);
        System.out.println(s);
        System.out.println(s1);

        Category category1 = jacksonObjectMapper.readValue(s, Category.class);
        Category category2 = objectMapper.readValue(s1, Category.class);

        System.out.println(s);
        System.out.println(s1);
    }
}
